/*强制提示没有登录，返回到首页*/
function backIndexPage(title, content) {
    layer.open({
        type: 1,
        title: title,
        area: ['300px', '200px'],
        anim: 5,
        shadeClose: false,
        content: content,
        btn: '知道了',
        cancel: function (layero, index) {
            window.location.href = '/pc/index.do'
        },
        yes: function (layero, index) {
            window.location.href = '/pc/index.do'
        }
    });
}
function MessageContent() {
    $.ajax({
        /*拿信息公告数据*/
        url: "/notices/findAllUserNotices.do",
        type: "post",
        data: {},
        success: function (data) {
            var html = ""
            $(".messageNotice .list").empty();
            var newData = data.data
            if (newData == 0) {
                $(".messageNotice .ivu-tabs-tabpane").append("<div class='noData'>暂无记录</div>")
            } else {
                for (i = 0; i < newData.length; i++) {
                    var item = newData[i];
                    html += "<li>" +
                        "<div class='head'><i class='iconfont openIcon icon-add'></i>" +
                        "<div class='title'>" + item.title + "</div>" +
                        "<div class='createTime'></div>" +
                        "</div>" +
                        "<div class='content'>" + item.content + "</div>" +
                        "</li>"
                }
                $(".messageNotice .list").append(html)
                $(".ivu-tabs-tabpane li .head").on("click", function () {
                    if ($(this).find("i").hasClass("icon-add")) {
                        $(this).find("i").removeClass("icon-add").addClass("icon-subtraction")
                        $(this).next().addClass("show")
                    } else {
                        $(this).find("i").removeClass("icon-subtraction").addClass("icon-add")
                        $(this).next().removeClass("show")
                    }
                })
            }

        },
        error: function (status) {
            bindLayerLittle("提示：", "网络繁忙,请检查网络")
        }
    })
}


$(".code").click(function () {
    $(".code").attr("src", "/u/code.do?" + Math.random());
});

function dataTable02() { /*提现记录的方法*/
    var oTable1 = $("#khtkjl").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "bPaginate": true,
        "sAjaxSource": "/recharge/findMoneyRecord.do",
        "fnServerData": retrieveData,
        "destroy": true,
        "bLengthChange": true,
        "bSort": false,
        "bAutoWidth": false,
        "bServerSide": true,
        'aLengthMenu': [15],
        "searching": false,
        "pagingType": "simple_numbers",
        "dom": "t<'tableinfo'i<'tableSearch'p>l>",
        "language": {
            "lengthMenu": "每页显示 _MENU_ 条记录",
            "zeroRecords": "没有检索到数据",
            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
            "info": "没有数据",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "search": "",
            "searchPlaceholder": "请输入关键字",
            "infoFiltered": "(从  _MAX_ 记录中搜索出结果)",
            "infoEmpty": "没有找到匹配的信息",
        },
        "columnDefs": [{
            "defaultContent": "",
            "targets": "_all"
        }],
        "columns": [{
            "data": "ordernum",
            "className": "ordernum-td"
        },
            {
                "data": "type",
                "className": "type-td"
            },
            {
                "data": "tikuanje",
                "className": "tikuanje-td"
            },
            {
                "data": "sqtime",
                "className": "sqtime-td"
            },
            {
                "data": "beizhu",
                "className": "beizhu-td"
            },
            {
                "data": "state",
                "className": "state-td"
            },
        ],
    })

    function retrieveData(sSource, aoData, fnCallback) {
        $.ajax({
            url: sSource,
            data: {
                "pageCount": aoData[0].value,
                "startIndex": aoData[3].value,
                "lineCount": aoData[4].value,
                "type": 1,
                "date3": StartDate1,
                "date4": EndDate1,
                "orderNum": orderNum,
                "model": model,
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (result) {
                var newJson = result.aaData
                if (newJson == "") {
                    $("#khtkjl .dataTables_empty").text("没有更多数据了")
                }
                fnCallback(result);

            },
            error: function (msg) {
            }
        });
    }
}

function GetDateStr(AddDayCount) {
    var dd = new Date();

    dd.setDate(dd.getDate() - AddDayCount);
    /*获取AddDayCount天前的日期 */
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1;
    /*获取当前月份的日期  */
    if (m < 10) {
        m = "0" + m
    }
    var d = dd.getDate();
    if (d < 10) {
        d = "0" + d
    }
    return y + "-" + m + "-" + d;
}
/*银行卡是否绑定的状态变化 */
function findMoneyPwd() {
    $.post('/users/getBankid.do', {}, function (result) {
        var newData = result.data
        if (newData == 0) {/*没有绑定银行卡 */
            $("#bankCard i").addClass("icon-notice")
            $("#bankCard span").text("未绑定")
            $("#bankCard").next().text("去绑卡")
        } else { /*绑定了银行卡 */
            $(".header").find(".name").val(newData.xingming)
            $(".header").find(".name").attr("disabled", "disabled")
            $("#bankCard i").removeClass("icon-notice").addClass("icon-hook")
            $("#bankCard span").text("已绑定")
            $("#bankCard").next().text("查看")
            $('#bankName').text(newData.kaihuhang);
            $('#bankNum').text(newData.bankNum);
            var html = ""
            $(".header fieldset").empty()
            html += "<legend data-v-23401bee=''>" +
                "<span class=''>" + newData.kaihuhang + newData.bankNum + "<span data-v-23401bee=''></span>（默认）</span>" +
                "</legend>" +
                "<input data-v-23401bee='' class='input xingming' disabled='disabled' value='姓名:" + newData.xingming + "'>" +
                "<input data-v-23401bee='' class='input bankNum' disabled='disabled' value='卡号:" + newData.bankNum + "'>" +
                "<input data-v-23401bee='' disabled='disabled' class='input kaihuhang' value='银行:" + newData.kaihuhang + "'>" +
                "<input data-v-23401bee='' disabled='disabled' class='input zhihang' value='支行: " + newData.zhihang + "'>"
            "<input data-v-23401bee='' disabled='disabled' class='input kaihudizhi' value='地址: " + newData.kaihudizhi + "'>"
            $(".header fieldset").append(html)
        }
        if (newData.zhifupass == undefined || newData.zhifupass == null) { /*还没绑定资金密码 */
            $("#setPwd i").addClass("icon-notice")
            $("#setPwd span").text("未设置")
            bankId = newData.id
            bankNum = newData.bankNum
            /*用户银行卡 */
            xingming = newData.xingming
            /*用户真实姓名 */
            kaihuhang = newData.kaihuhang
            /*用户开户行 */
            kaihudizhi = newData.kaihudizhi
            /*用户开户地址 */
        } else {
            $(".newpass").remove()
            $(".newpass1").remove()
            $("#setPwd i").removeClass("icon-notice").addClass("icon-hook")
            $("#setPwd span").text("已设置")
            $(".header").find(".zhifupass").attr("placeholder", "请输入当前资金密码")
            $("#setPwd").next().text("修改")
            $(".zhifupass").after("<input data-v-23401bee='' type='password' placeholder='请输入新资金密码' class='input inputBottom newpass' autocomplete='off'><input data-v-23401bee='' autocomplete='off' type='password' placeholder='请再次输入新资金密码' class='input inputBottom newpass1'>")
            zfpassword = newData.zhifupass
            bankId = newData.id
            bankNum = newData.bankNum
            xingming = newData.xingming
            kaihuhang = newData.kaihuhang
            kaihudizhi = newData.kaihudizhi
        }
    });
}
/*在线方式页面的数据渲染*/
function OnLineDateRenders(number) {
    $(".zaixianzf").empty();
    var html1 = ""
    if (zhifubianhao.indexOf(number) != -1) {
        html1 += "<li class=''><input class='typeValue' style='display:none' value=" + number + "><img src='http://wcweb-1254050727.file.myqcloud.com/backend.rechargecenter.cc/upload/pay_manage/20180823/57d34fe70bd55078a1148fc9038c5f06.png' alt='图标'>" +
            "<p class='channel-name' style='margin-top:20px;margin-bottom:15px;'>" + obj[number] + "</p>" +
            "<p style='color: rgb(188, 137, 46);'>转账支付、安全、快捷、高效</p>" +
            "<i class='iconfont icon-choose' style='display:none'></i>" +
            "</li>"
    }
    $(".zaixianzf").append(html1)
    $(".zaixianzf li").eq(0).addClass("redBorder")
    $(".zaixianzf li").eq(0).find(".icon-choose").show()
    countValue = $(".zaixianzf li").eq(0).find(".typeValue").val();
    $(".input-typeName").attr("value", countValue)
    $(".zxzf .jine").attr("value", $(".jine").val())
}

function OnLineDateRender(number1, number2) { /*两个在线支付接口存在的*/
    $(".zaixianzf").empty();
    var html1 = ""
    if (zhifubianhao.indexOf(number1) != -1) {
        console.log("进来了")
        html1 += "<li class=''><input class='typeValue' style='display:none' value=" + number1 + "><img src='http://wcweb-1254050727.file.myqcloud.com/backend.rechargecenter.cc/upload/pay_manage/20180823/57d34fe70bd55078a1148fc9038c5f06.png' alt='图标'>" +
            "<p class='channel-name' style='margin-top:20px;margin-bottom:15px;'>" + obj[number1] + "</p>" +
            "<p style='color: rgb(188, 137, 46);'>转账支付、安全、快捷、高效</p>" +
            "<i class='iconfont icon-choose' style='display:none'></i>" +
            "</li>"
    }
    if (zhifubianhao.indexOf(number2) != -1) {
        html1 += "<li class=''><input class='typeValue' style='display:none' value=" + number2 + "><img src='http://wcweb-1254050727.file.myqcloud.com/backend.rechargecenter.cc/upload/pay_manage/20180823/57d34fe70bd55078a1148fc9038c5f06.png' alt='图标'>" +
            "<p class='channel-name' style='margin-top:20px;margin-bottom:15px;'>" + obj[number2] + "</p>" +
            "<p style='color: rgb(188, 137, 46);'>转账支付、安全、快捷、高效</p>" +
            "<i class='iconfont icon-choose' style='display:none'></i>" +
            "</li>"
    }
    $(".zaixianzf").append(html1)
    $(".zaixianzf li").eq(0).addClass("redBorder")
    $(".zaixianzf li").eq(0).find(".icon-choose").show()
    countValue = $(".zaixianzf li").eq(0).find(".typeValue").val();
    $(".input-typeName").attr("value", countValue)
    $(".zxzf .jine").attr("value", $(".jine").val())
    $(".zaixianzf li").on("click", function () {
        countValue = $(this).find(".typeValue").val()
        $(".input-typeName").attr("value", countValue)
        $(this).addClass("redBorder").siblings().removeClass("redBorder")
        $(this).find(".icon-choose").show()
        $(this).siblings().find(".icon-choose").hide()
    })
}
/*扫码方式页面的数据渲染*/
function CodeDataRender(newData, type) {
    var html = ""
    $(".shaomazf").empty();
    $(".zhanghaoType").text(type + "账号")
    $(".zhanghao").attr("placeholder", "请输入" + type + "账号")
    $(".recharge-header .title").text("扫码支付")
    for (i = 0; i < newData.length; i++) {
        if (newData[i].paymentType == type && newData[i].state != 0) {
            array.push(i)
            html += "<li class=''><img src='http://wcweb-1254050727.file.myqcloud.com/backend.rechargecenter.cc/upload/pay_manage/20180823/57d34fe70bd55078a1148fc9038c5f06.png' alt='图标'>" +
                "<p class='channel-name' style='margin-top:20px;margin-bottom:15px;'>" + newData[i].name + "</p>" +
                "<p style='color: rgb(188, 137, 46);'>转账支付、安全、快捷、高效</p>" +
                "<i class='iconfont icon-choose' style='display:none'></i>" +
                "</li>"
        }
    }
    $(".shaomazf").append(html)
    $(".shaomazf li").eq(0).addClass("redBorder")
    $(".shaomazf li").eq(0).find(".icon-choose").show()
    $(".TypeCode img").attr("src", "/d/cp/" + newData[array[0]].pictureAddress)
    zfpingtai = $(".shaomazf li").eq(0).find(".channel-name").text();
    $(".shaomazf li").on("click", function () {
        var index = $(this).index();
        $(this).addClass("redBorder").siblings().removeClass("redBorder")
        $(this).find(".icon-choose").show()
        $(this).siblings().find(".icon-choose").hide()
        $(".TypeCode img").attr("src", "/d/cp/" + newData[array[index]].pictureAddress)
        zfpingtai = $(this).find(".channel-name").text();
    })
}

/*在线支付的提交方法*/
function OnLinezhifu() {
    var payType = "";
    $(".button-zaixianzhif").on("click", function (e) {
        var result = $(".zxzf .jine").val()
        console.log(result)
        if (!result) {
            bindLayerLittle("提示：", "充值金额不能为空")
            return false;
        }
        if (result <= 0) {
            bindLayerLittle("提示：", "充值金额不能低于0元")
            return false;
        }
        if (result > 100000000) {
            bindLayerLittle("提示：", "单笔充值金额不能超过1亿元")
            return false;
        }
        console.log($(".zxzf .input-typeName").val(), '我读取回来的值')

        if ($(".zxzf .input-typeName").val() == 4) {
            payType = "ALIQR";//支付宝
        } else if ($(".zxzf .input-typeName").val() == 2) {
            payType = "WXQR";
        }
        $.ajax({ //在线支付的接口
            url: "/pc/rechargeIndex.do",
            type: "post",
            data: {"type": payType, "amount": result},
            dataType: "text",
            success: function (data) {
                window.location.href = data;
                console.log(data, '============================================> pc')
            }
        });
    })
}
/*扫码支付方式的提交事件*/
function Codezhifu() {
    var state = true;
    var CZmoney
    var zhanghao
    $(".button-shaomazhif").on("click", function (e) {
        CZmoney = $(".rechargeIndex .smzf .jine").val();
        zhanghao = $(".rechargeIndex .smzf .zhanghao").val();
        if (CZmoney.trim() == "" || !checkValueIsNumber(CZmoney) || CZmoney < 10) {
            bindLayerLittle("提示：", "充值金额不得为空,且金额不能低于10元")
            return
        }
        if (CZmoney > 100000000) {
            bindLayerLittle("提示：", "单笔充值金额不能超过一亿元")
            return
        }
        if (zhanghao.trim() == "") {
            bindLayerLittle("提示：", "存款人账号不得为空")
            return
        }
        $.ajax({
            type: "post",
            url: "/u/userMoney.do",
            success: function (data) {
                if (data.message == 0) {
                    $.ajax({
                        url: "/pay/shoudongcz.do",
                        type: "post",
                        data: {
                            zhifupt: zfpingtai,
                            fukuanje: CZmoney,
                            zhifuzh: zhanghao,
                            ckname: zhanghao,
                            hydengji: zfpingtai,
                        },
                        success: function (data) {
                            bindLayerLittle("提示：", "转账成功，等待客服确认")
                            window.location.href = "/pc/personal.do#czrecord"
                        },
                        error: function (status) {
                            bindLayerLittle("提示：", "网络繁忙,请检查网络")
                        },
                    })
                } else {
                    $(".code").attr("src", "/u/code.do?" + Math.random());
                    $("#div-i-noticeGenDan2").modal("show");
                    $("#code").val("")
                    $(".tips").text("")
                }
            },
        });
    })

    $("#confirm1").on("click", function () {
        if (state) {
            state = false;
            $.ajax({
                url: "/pay/shoudongcz.do",
                type: "post",
                data: {
                    zhifupt: zfpingtai,
                    fukuanje: CZmoney,
                    zhifuzh: zhanghao,
                    ckname: zhanghao,
                    hydengji: zfpingtai,
                    code: $("#code").val(),
                },
                success: function (data) {
                    var yanzhengma = $("#code").val()
                    if (yanzhengma.length > 4) {
                        $(".tips").text("")
                    }
                    if (data.data == "验证码输入不正确! ") {
                        $(".tips").text("验证码不正确，请重新输入")
                        state = true;
                    } else {
                        $("#div-i-noticeGenDan2").modal("hide");
                        bindLayerLittle("提示：", "转账成功，等待客服确认")
                        $(".chooseGroup .zhanghao").val("")
                        window.location.href = "/pc/personal.do#czrecord"
                    }
                }
            })
        }
    })
}

/* 修改密码方法 */
function updatePassword() {
    var pwd1 = $('#pwd1').val();
    var pwd2 = $('#pwd2').val();
    var pwd3 = $('#pwd3').val();
    if (pwd1 == '' || pwd2 == '' || pwd3 == '') {
        bindLayerLittle("提示：", '请输入有效的密码信息!');
        return;
    }
    if (pwd2 != pwd3) {
        bindLayerLittle("提示：", '在次确认密码不对!');
        return;
    }

    $.post('/u/changePass.do', {
        pass: pwd1,
        npass: pwd2
    }, function (result) {
        if (result.message == 0) {
            bindLayerLittle("提示：", result.data);
            return;
        }
        $('#pwd1').val('');
        $('#pwd2').val('');
        $('#pwd3').val('');
        bindLayerLittle("提示：", result.data);

    });
}

var checkIsNumber = function (s1) { /*判断是否为数字的方法*/
    if (!s1) {
        return false
    }
    for (var i = 0; i < s1.length; i++) {
        var letter = s1[i]
        if (NUMBERS.indexOf(letter) == -1) {
            return false
        }
    }
    return true
}

var checkPassWord = function (s2) { /*判断是否为密码的方法*/
    if (!s2) {
        return false
    }
    for (var j = 0; j < s2.length; j++) {
        var letter = s2[j]
        if (PASSWORD.indexOf(letter) == -1) {
            return false
        }
    }
    if (s2.length < 6 || s2.length > 16) {
        return false
    }
    return true
}


function BindRecharge() {
    $.ajax({
        /*绑定银行卡的接口*/
        url: "/pay/acountBank.do",
        type: "post",
        data: {},
        success: function (data) {
            if (data.data == 0 || data.data == "") {
                ReChargeUl.find("#yhkzzli").addClass("hide").removeClass("visible");
            } else {
                ReChargeUl.find("#yhkzzli").removeClass("hide").addClass("visible");
            }
        }
    })

    $.ajax({
        /*在线支付的接口*/
        url: "/pay/findRecharge.do",
        type: "post",
        data: {},
        success: function (data) {
            var zhifubianhao
            var zhifubianhao1
            console.log(data.data[0].p_ChannelId.split(","))
            zhifubianhao = data.data[0].p_ChannelId.split(",")
            if (data.data.length > 1) {
                zhifubianhao1 = data.data[1].p_ChannelId.split(",")
            }
            zhifubianhao.pop()
            $.ajax({
                url: "/pay/scavengingPayment.do", /*扫码支付接口*/
                type: "post",
                data: {},
                success: function (data) {
                    if (data.data == 0) {
                        if (zhifubianhao.indexOf("1") != -1 || zhifubianhao.indexOf("2") != -1) {
                            ReChargeUl.find("#weixinli").removeClass("hide").addClass("visible");
                            /*如果有微信支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#weixinli").addClass("hide").removeClass("visible");
                        }

                        if (zhifubianhao.indexOf("3") != -1 || zhifubianhao.indexOf("4") != -1) {
                            ReChargeUl.find("#zhifubaoli").removeClass("hide").addClass("visible");
                            /*如果有QQ支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#zhifubaoli").addClass("hide").removeClass("visible");
                        }
                        if (zhifubianhao.indexOf("5") != -1 || zhifubianhao.indexOf("6") != -1) {
                            ReChargeUl.find("#yinlianli").removeClass("hide").addClass("visible");
                            /*如果有支付宝支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#yinlianli").addClass("hide").removeClass("visible");
                        }

                        if (zhifubianhao.indexOf("7") != -1 || zhifubianhao.indexOf("8") != -1) {
                            ReChargeUl.find("#yinlianli").removeClass("hide").addClass("visible");
                            /*如果有银联支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#yinlianli").addClass("hide").removeClass("visible");
                        }
                        $(".recharge").find(".visible").eq(0).addClass("redBorder")
                    } else {
                        var scave
                        var newData = data.data
                        var paymentType = [];
                        for (i = 0; i < newData.length; i++) {
                            if (newData[i].state != 0) { /*启用*/
                                paymentType.push(newData[i].paymentType)
                            }
                        }
                        if (zhifubianhao.indexOf("1") != -1 || zhifubianhao.indexOf("2") != -1 || paymentType.indexOf("微信") != -1) {
                            ReChargeUl.find("#weixinli").removeClass("hide").addClass("visible");
                            /*如果有微信支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#weixinli").addClass("hide").removeClass("visible");
                        }

                        if (zhifubianhao.indexOf("3") != -1 || zhifubianhao.indexOf("4") != -1 || paymentType.indexOf("支付宝") != -1) {
                            ReChargeUl.find("#zhifubaoli").removeClass("hide").addClass("visible");
                            /*如果有支付宝支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#zhifubaoli").addClass("hide").removeClass("visible");
                        }

                        if (zhifubianhao.indexOf("5") != -1 || zhifubianhao.indexOf("6") != -1) {
                            ReChargeUl.find("#QQli").removeClass("hide").addClass("visible");
                            /*如果有QQ支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#QQli").addClass("hide").removeClass("visible");
                        }

                        if (zhifubianhao.indexOf("7") != -1 || zhifubianhao.indexOf("8") != -1) {
                            ReChargeUl.find("#yinlianli").removeClass("hide").addClass("visible");
                            /*如果有银联支付的接口就显示*/
                        } else {
                            ReChargeUl.find("#yinlianli").addClass("hide").removeClass("visible");
                        }
                        $(".recharge").find(".visible").eq(0).addClass("redBorder")
                    }
                },
                error: function (status) {
                    bindLayerLittle("提示：", "网络繁忙,请检查网络")
                }
            })
        },
        error: function (status) {
            bindLayerLittle("提示：", "网络繁忙,请检查网络")
        }
    })

}

/*提现*/
function withdraw() {
    $(".withdraw").bind("input propertychange", function () {
        if ($(".bankMoney").val() != "" && $(".capital").val() != "") {
            $(".withdraw-button").attr("disabled", false)
        } else {
            $(".withdraw-button").attr("disabled", "disabled")
        }
    })

    $(".withdraw-button").on("click", function () {
        if ($(".bankMoney").val() < 100) {
            bindLayerLittle("提示：", "提现金额不能少于100元,且必须为数字整数")
            return;
        }

        if ($(".bankMoney").val() > 20000) {
            bindLayerLittle("提示：", "提现金额不能超过2万元,且必须为数字整数")
            return;
        }
        var zijinPass = $(".capital").val()
        if (!checkPassWord(zijinPass)) {
            bindLayerLittle("提示：", "密码必须是6~16位可包含字母以及数字")
            return
        }
        if (zijinPass != zfpassword) {
            bindLayerLittle("提示：", "输入的密码不对，请重新输入")
            return
        }
        tikuanContent = $(".beizhu").val()
        if (tikuanContent.length > 100) {
            bindLayerLittle("提示：", "备注内容过长")
            return
        }

        $.ajax({
            url: "/users/userDamal.do",
            type: "post",
            data: {
                money: $(".bankMoney").val()
            },
            success: function (data) {
                $(".span-c-currentDaMa").text(data.data)
                var message = data.message;
                var status = message.substring(0, 1)
                var shouxufei = message.substring(2, message.length)
                var percentage = shouxufei * 100 + "%";
                /* "若要继续申请提现，将收取"+percentage+"的手续费"+shouxufei* $(".tixianMoneyValue").val()+"元" */
                if (status == 0) {
                    layer.open({
                        type: 1,
                        area: ['300px', "200px"],
                        title: "提示：",
                        shadeClose: true,
                        anim: 3,
                        content: data.data,
                        btn: ['确认', '取消'],
                        yes: function (layero, index) {
                            $.ajax({
                                url: "/users/tikuansq.do",
                                type: "post",
                                data: {
                                    tikuanje: $(".bankMoney").val(),
                                    zhifupass: zijinPass,
                                    beizhu: tikuanContent,
                                },
                                success: function (data) {
                                    layer.close(layer.index);
                                    if (data.message == 0) {
                                        bindLayerLittle("提示：", data.data)
                                        return;
                                    } else {
                                        bindLayerLittle("提示：", data.data)
                                        window.location.href = '/pc/personal.do#txrecord';
                                    }
                                },
                                error: function (status) {
                                    bindLayerLittle("提示：", "网络繁忙,请检查网络")
                                },
                            })
                        }
                    });
                } else {
                    $.ajax({
                        url: "/users/tikuansq.do",
                        type: "post",
                        data: {
                            tikuanje: $(".bankMoney").val(),
                            zhifupass: zijinPass,
                            beizhu: tikuanContent,
                        },
                        success: function (data) {
                            if (data.message == 0) {
                                bindLayerLittle("提示：", data.data)
                                return;
                            } else {
                                bindLayerLittle("提示：", data.data)
                                window.location.href = '/pc/personal.do#txrecord';
                            }
                        },
                        error: function (status) {
                            bindLayerLittle("提示：", "网络繁忙,请检查网络")
                        },
                    })
                }
            },
            error: function (status) {
                bindLayerLittle("提示：", "网络繁忙,请检查网络")
            }
        })
    })
}

function dataTable_myLiushui() {
    var OTble = $("#table_liushui").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "bPaginate": true,
        "sAjaxSource": "/users/details.do",
        "fnServerData": retrieveData,
        "destroy": true,
        "bLengthChange": true,
        "bSort": false,
        "bAutoWidth": false,
        "bServerSide": true,
        'aLengthMenu': [10],
        "searching": false,
        "pagingType": "simple_numbers",
        "dom": "t<'tableinfo'i<'tableSearch'p>l>",
        "language": {
            /* " lengthMenu": "每页显示 _MENU_ 条记录", */
            "zeroRecords": "没有检索到数据",
            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
            "info": "没有数据",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "search": "",
            "searchPlaceholder": "请输入关键字",
            "infoFiltered": "(从  _MAX_ 记录中搜索出结果)",
            "infoEmpty": "没有找到匹配的信息",
        },
        "columnDefs": [{
            "defaultContent": "",
            "targets": "_all"
        }],
        "aoColumns": [{
            "data": "bdtype",
            "className": "bdtype-td"
        },
            {
                "data": "bdqjine",
                "className": "bdqjine-td"
            },
            {
                "data": "bdjine",
                "className": "bdjine-td"
            },
            {
                "data": "bdhjine",
                "className": "bdhjine-td"
            },
            {
                "data": "createtime",
                "className": "createtime-td"
            },
        ],
    })

    function retrieveData(sSource, aoData, fnCallback) {
        $.ajax({
            url: sSource,
            data: {
                "pageCount": aoData[0].value,
                "startIndex": aoData[3].value,
                "lineCount": aoData[4].value,
                "bdtype": bdtype,
                "createtime": StartDate2,
                "ordernum": EndDate2,
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (result) {
                var newData = result.aaData
                for (var i = 0; i < newData.length; i++) {
                    var item = newData[i]
                    if (item.state == true) {
                        item.bdjine = "+" + item.bdjine
                        console.log(item.bdjine)
                    } else {
                        item.bdjine = "-" + item.bdjine
                    }
                    if (item.bdjine == 0) {
                        return;
                    }
                }
                result.aaData = newData;
                fnCallback(result);
            },
            error: function (msg) {
            }
        });
    }
}

function dataTable_myOrders() {
    var OTble = $("#table_touzhu").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "bPaginate": true,
        "sAjaxSource": "/orders/myOrders.do",
        "fnServerData": retrieveData,
        "destroy": true,
        "bLengthChange": true,
        "bSort": false,
        "bAutoWidth": false,
        "bServerSide": true,
        'aLengthMenu': [10],
        "searching": false,
        "pagingType": "simple_numbers",
        "dom": "t<'tableinfo'i<'tableSearch'p>l>",
        "language": {
            "zeroRecords": "没有检索到数据",
            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
            "info": "没有数据",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "search": "",
            "searchPlaceholder": "请输入关键字",
            "infoFiltered": "(从  _MAX_ 记录中搜索出结果)",
            "infoEmpty": "没有找到匹配的信息",
        },
        "columnDefs": [{
            "defaultContent": "",
            "targets": "_all"
        }],
        "aoColumns": [{
            "data": "id",
            "className": "id-td hidden-c"
        },
            {
                "data": "cname1",
                "className": "cname1-td"
            },
            {
                "data": "period",
                "className": "period-td"
            },
            {
                "data": "orderdate",
                "className": "orderdate-td timedate"
            },
            {
                "data": "lottercount",
                "className": "lottercount-td"
            },
            {
                "data": "acount",
                "className": "acount-td"
            },
            {
                "data": "goalmoney",
                "className": "goalmoney-td"
            },
            {
                "data": "states",
                "className": "states-td"
            },
            {
                "data": null,
                "defaultContent": "<button class='butt-xiangqing'>投注详情</button>"
            },
        ],
    })

    function retrieveData(sSource, aoData, fnCallback) {
        $.ajax({
            url: sSource,
            data: {
                "pageCount": aoData[0].value,
                "startIndex": aoData[3].value,
                "lineCount": aoData[4].value,
                "state": state,
                "cname": cname,
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (result) {
                var newData = result.aaData
                for (var i = 0; i < newData.length; i++) {
                    var item = newData[i]
                    if (item.state === 1) {
                        item.states = "待开奖"
                    } else if (item.state === 7) {
                        item.states = "已撤单"
                    } else if (item.state === 8) {
                        item.states = "平台退款"
                    } else if (item.state === 6) {
                        item.states = "和局中奖"
                    } else if (item.state === 2 || item.goalmoney === 0.00) {
                        item.states = "未中奖"
                    } else if (item.state === 3 || item.goalmoney !== 0.00) {
                        item.states = "已中奖"
                    }
                }
                result.aaData = newData;
                fnCallback(result);
            },
            error: function (msg) {
            }
        });
    }
}

/* 棋牌下注记录  */
function dataTable_chessTouzhu() {
    var OTble = $("#chess_touzhu").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "bPaginate": true,
        "sAjaxSource": "/b/historicalDownloads.do",
        "fnServerData": retrieveData,
        "destroy": true,
        "bLengthChange": true,
        "bSort": false,
        "bAutoWidth": false,
        "bServerSide": true,
        'aLengthMenu': [10],
        "searching": false,
        "pagingType": "simple_numbers",
        "dom": "t<'tableinfo'i<'tableSearch'p>l>",
        "language": {
            "zeroRecords": "没有检索到数据",
            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
            "info": "没有数据",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "search": "",
            "searchPlaceholder": "请输入关键字",
            "infoFiltered": "(从  _MAX_ 记录中搜索出结果)",
            "infoEmpty": "没有找到匹配的信息",
        },
        "columnDefs": [{
            "defaultContent": "",
            "targets": "_all"
        }],
        "aoColumns": [{
            "data": "id",
            "className": "id-td hidden-c"
        },
            {
                "data": "cname1",
                "className": "cname1-td"
            },
            {
                "data": "issueNumber",
                "className": "issueNumber-td"
            },
            {
                "data": "bettingtime",
                "className": "bettingtime-td"
            },
            {
                "data": "totalBet",
                "className": "totalBet-td"
            },
            {
                "data": "winningAmount",
                "className": "winningAmount-td"
            },
            {
                "data": "tableNumber",
                "className": "tableNumber-td"
            },
            {
                "data": "status",
                "className": "status-td"
            },
            {
                "data": null,
                "defaultContent": "<button class='butt-xiangqing'>投注详情</button>"
            },
        ],
    })

    function retrieveData(sSource, aoData, fnCallback) {
        $.ajax({
            url: sSource,
            data: {
                "pageCount": aoData[0].value,
                "startIndex": aoData[3].value,
                "lineCount": aoData[4].value,
                "status": status,
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (result) {
                var newData = result.aaData
                for (var i = 0; i < newData.length; i++) {
                    var item = newData[i]
                    item.cname1 = "百家乐";
                    if (item.state == 0) { /* 待开奖状态 */
                        item.status = "待开奖"
                    } else if (item.state == 1) { /* 已开奖状态，判断是否中奖 */
                        if (item.status == 0) { /* 未中奖  */
                            item.status = "未中奖"
                        } else if (item.status == 1) { /* 已中奖  */
                            item.status = "已中奖"
                        }
                    } else if (item.state == 2) { /* 开奖数据异常 */
                        item.status = "开奖异常，已退款"
                    }
                }
                result.aaData = newData;
                fnCallback(result);
            },
            error: function (msg) {
            }
        });
    }
}

function SYlotter() {
    $.ajax({
        type: "post",
        url: "/syLotterr.do",
        "data": {},
        success: function (data) {
            $(".select-width").empty();
            var newData = data.data;
            console.log(newData)
            var html = "<option value=''>全部</option>";
            for (i = 0; i < newData.length; i++) {
                var item = newData[i]
                html += "<option value='" + item.cname + "'>" + item.name + "</option>"
            }
            $(".select-width").append(html)

        },
        error: function (status) {
        }
    })
}

function findXiangqing() {
    $("#table_touzhu").on("click", '.butt-xiangqing', function (e) {
        $(".chess-header").hide();
        $("#addAndEditModal").modal("show")
        var id = $(this).parent().siblings().parent().find(".id-td").text()
        console.log(id)
        var date1 = $(e.currentTarget).closest("tr").find(".timedate").text()
        $.ajax({
            type: "post",
            url: "/orders/touzhuRecord.do",
            "data": {
                'id': id
            },
            success: function (data) {
                var datas = data.data
                var body = $(".modal-body")
                body.empty()
                var awardNumber = datas['lotternum']
                if (awardNumber == null || awardNumber == "") {
                    awardNumber = "待开奖"
                }
                body.append("<p><span class='backbet'>投注期号：</span><input value='" + datas['period'] + "'class='form-control backCor' id='input-i-name' readonly /></p><p><span class='backbet'>开奖号码：</span><input value='" + awardNumber + "' class='form-control backCor' id='input-i-nicheng' readonly /></p>")
                for (i = 1; i < 41; i++) {
                    if (datas['str' + i] != '' && datas['str' + i] != null) {
                        body.append("<p><span>投注玩法：</span><input value='" + datas['cplay' + i] + "' class='form-control' readonly /></p><p><span>投注号码：</span><input value='" + datas['str' + i] + "' class='form-control' readonly /></p>")
                    }
                }

            }
        });
    })
}

function findUserDrawingInfo() {
    $.post('/recharge/findUserDrawingInfo.do', {}, function (result) {
        var data = $.parseJSON(result).data;
        var time = data.qukuanshijian;
        var date = time.substring(0, 2) + ":" + time.substring(2, 7) + ":" + time.substring(7, 9);
        $('.user-balance').text(data.yue + " 元");
        /*用户余额*/
        $('.user-term').text(data.danbixiane + " 元");
        /*单笔限额 */
        $('.user-money').text(data.ketixianjine + " 元");
        /*可提现金额*/
        $('.user-counts').text(data.jinriyitikuancishu + " 次");
        /*已提款次数 */
        $('.user-time').text(date);
        /*每日提款时间 */
        $('.user-termCounts').text(data.meirixianzhicishu + " 次");
        /*提款限制次数 */
        $('.user-jine').text(data.jinriyitijine + " 元");
        /*今日已提款金额 */
        $('.user-termJine').text(data.meirixianzhijine + " 元");
        /*每日限制金额*/
    }, 'text');
}

var checkValueIsNumber = function (string) {
    var stringValue = Number(string)
    if (isNaN(stringValue) || stringValue == null || stringValue == undefined) {
        return false
    }
    if (stringValue == "") {
        return false
    }
    for (var i = 0; i < stringValue.length; i++) {
        var letter = stringValue[i]
        if (!numberString.includes(letter)) {
            return false
        }
    }
    if (stringValue.length > 1) {
        if (stringValue[0] == "0") {
            return false
        }
    }
    if (stringValue < 0) {
        return false
    }
    return true
}

//根据AddMonthCount的值获取到当月日期
function GetMonthStr(AddMonthCount) {
    var dd = new Date();
    dd.setMonth(dd.getMonth() - AddMonthCount);
    /*  获取AddDayCount天前的日期 */
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1;
    /*  获取当前月份的日期 */
    if (m < 10) {
        m = "0" + m;
    }
    var d = dd.getMonth();
    if (d < 10) {
        d = "0" + d;
    }
    return y + "-" + m;
}